package cluster

import (
	"go-redis/interface/resp"
	"go-redis/resp/reply"
)

// ping命令的处理函数
func renameFunc(cluster *ClusterDatabase, c resp.Connection, cmdArgs [][]byte) resp.Reply {

	if len(cmdArgs) != 3 {
		return reply.MakeErrReply("ERR wrong number of arguments for 'rename' command")
	}

	srcKey := string(cmdArgs[1])
	destKey := string(cmdArgs[2])

	srcNode := cluster.peerPicker.SelectNode(srcKey)
	destNode := cluster.peerPicker.SelectNode(destKey)

	if srcNode != destNode {
		return reply.MakeErrReply("ERR rename must within one slot in cluster mode")
	}
	return cluster.dispatcher(srcNode, c, cmdArgs)

}
